package com.example.demo.controller;

import com.example.demo.pojo.Teacher;
import com.example.demo.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Transactional
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @ApiOperation("获取老师的课程")
    @RequestMapping("/getCourse")
    public String getCourse(HttpSession session, Model model){
       Teacher teacher= (Teacher) session.getAttribute("teacher");

        Teacher teacher1=teacherService.getCourse(teacher.getTid());
        model.addAttribute("teacher",teacher1);
        return "teacher/teacherCourse";
    }
    @ApiOperation("获取老师的课程")
    @RequestMapping("/getCourse1")
    public String getCourse1(HttpSession session, Model model){
        Teacher teacher= (Teacher) session.getAttribute("teacher");

        Teacher teacher1=teacherService.getCourse(teacher.getTid());
        model.addAttribute("teacher",teacher1);
        return "teacher/teacherCourse1";
    }
    @ApiOperation("foreach批量添加数据")
    @RequestMapping("/insertMore")
    public String insertMore(){
        List teacherList=new ArrayList<Teacher>();
        Teacher teacher=new Teacher(12112405,"hisr",1815,"hfahf15454");
        teacherList.add(teacher);
        Teacher teacher1=new Teacher(12,"hello",1815,"hfahf15454");
        teacherList.add(teacher1);
        teacherService.insertTeacher(teacherList);
        return "teacher/teacher";
    }
    @ApiOperation("if判断查询")
    @RequestMapping("/selectTest")
    public String selectTest(){
        Map<String ,Object> map=new HashMap<String ,Object>();
        /*map.put("ttel",'');*/
      /*  map.put("tid",12);*/
        Teacher teacher=teacherService.selectTest(map);
        System.out.println(teacher);
        return "teacher/teacher";
    }



}
